package com.king.hrmsdev.service;

import com.king.hrmsdev.entity.Aleave;
import com.king.hrmsdev.entity.Echeck;
import com.king.hrmsdev.mapper.AttendanceMapper;
import com.king.hrmsdev.pojo.Valeaveinfo;
import com.king.hrmsdev.pojo.Vecheckinfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Auther:SnakeKing
 * @Date: 2019-09-22
 * @Description: com.king.hrmsdev.service
 * @version:1.0
 */
@Service
public class AttendanceService {

    @Resource
    private AttendanceMapper attendanceMapper;

    public List<Valeaveinfo> Findallaleave() {
        List<Valeaveinfo> valeaveinfoList = attendanceMapper.Findallaleave();
        return valeaveinfoList;
    }


    public int Approvalaleave(int aleave_id) {
        int flag = 1;
        try {
            attendanceMapper.Approvalaleave(aleave_id);
        } catch (Exception e) {
            flag = 0;
        } finally {
            return flag;
        }

    }

    public int Refusealeave(int aleave_id) {
        int flag = 1;
        try {
            attendanceMapper.Refusealeave(aleave_id);
        } catch (Exception e) {
            flag = 0;
        } finally {
            return flag;
        }

    }

    public int Insertaleave(Aleave aleave) {

        int flag = 1;
        try {
            attendanceMapper.Insertaleave(aleave);
        } catch (Exception e) {
            flag = 0;
        } finally {
            return flag;
        }

    }

    public List<Valeaveinfo> AleaveFuzzyreward(Map<String, Object> map) {
        Integer job_id = (Integer) map.get("job_id");
        Integer aleave_id = (Integer) map.get("aleave_id");
        String ename = (String) map.get("ename");
        Object btime = map.get("btime");
        Object etime = map.get("etime");
        if (btime == "") {
            btime = null;
        }
        if (etime == "") {
            etime = null;
        }


        Map map1 = new HashMap();

        map1.put("job_id", job_id);
        map1.put("aleave_id", aleave_id);
        map1.put("ename", ename);
        map1.put("btime", btime);
        map1.put("etime", etime);

        List list = attendanceMapper.AleaveFuzzyreward(map1);

        return list;

    }


    //考勤记录

    public List<Vecheckinfo> Findallecheck() {
        List<Vecheckinfo> vecheckinfoList = attendanceMapper.Findallecheck();
        return vecheckinfoList;
    }

    public int Insertecheck(Echeck echeck) {
        int flag = 1;
        try {
            attendanceMapper.Insertecheck(echeck);
        } catch (Exception e) {
            flag = 0;
        } finally {
            return flag;
        }
    }

    public int Updateecheck(Echeck echeck) {
        int flag = 1;
        try {
            attendanceMapper.Updateecheck(echeck);
        } catch (Exception e) {
            flag = 0;
            System.out.println("service  ::  echeck++++++++" + echeck);
        } finally {
            return flag;
        }

    }//可能有bug

    public int Deleteecheck(int echeck_id) {
        int flag = 1;
        try {
            attendanceMapper.Deleteecheck(echeck_id);
        } catch (Exception e) {
            flag = 0;
        } finally {
            return flag;
        }

    }

    public List<Vecheckinfo> EcheckFuzzyreward(Map<String, Object> map) {
        Integer job_id = (Integer) map.get("job_id");
        Integer echeck_id = (Integer) map.get("echeck_id");
        String ename = (String) map.get("ename");
        Object opentime = map.get("opentime");
        Object closetime = map.get("closetime");

        Map map1 = new HashMap();

        map1.put("job_id", job_id);
        map1.put("echeck_id", echeck_id);
        map1.put("ename", ename);
        map1.put("opentime", opentime);
        map1.put("closetime", closetime);

        List list = attendanceMapper.EcheckFuzzyreward(map1);

        return list;
    }
}
